<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ list.title }}</span>
          <!-- 一张图片 -->
          <div>
            <!-- v-if判断有几张图片 -->
            <img
              class="thumb"
              :src="list.cover.images[0]"
              v-if="list.cover.type === 1"
            />
          </div>
        </div>
        <!-- 三张图片 -->
        <div class="thumb-box" v-if="list.cover.type === 3">
          <img
            class="thumb"
            v-for="(item, index) in list.cover.images"
            :key="index"
            :src="item"
          />
        </div>
      </template>

      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ list.aut_name }}</span
            >&nbsp;&nbsp; <span>{{ list.comm_count }}</span
            >&nbsp;&nbsp;
            <span>{{ list.pubdate }}</span>
          </div>

          <!-- 反馈按钮 -->
          <van-icon name="cross" @click="closeFn" />
        </div>
      </template>
    </van-cell>
    <!-- 反馈组件 -->
    <van-action-sheet
      v-model="show"
      :actions="actions"
      @select="onSelect"
      get-container="body"
      :cancel-text="cancelText"
    />
  </div>
</template>

<script>
import { oneArray, secondActions } from '@/api/PanelLaying'

export default {
  // 接受ArticleList传过来的值
  props: {
    list: {
      type: Object,
      require: true
    }
  },
  data () {
    return {
      show: false, // 反馈组件显示状态
      actions: oneArray, // 一级面板
      cancelText: '取消'// 默认取消键的内容
    }
  },
  methods: {
    onSelect (action, index) {
      console.log(action, index)
      // 判断点击的name
      if (action.name === '不感兴趣') {
        this.$emit('remove', this.list, action)
      } else if (action.name === '反馈垃圾内容') {
        // 铺设二级面板
        this.actions = secondActions
        // 添加返回
        secondActions[0].name = '返回'
      } else if (action.name === '拉黑作者') {

      } else if (action.name === '返回') {
        // 把一级面板的数据替换上去
        this.actions = oneArray
      } else {
        this.$emit('remove', this.list, action)
      }
    },
    // 点击按钮改变show的默认值
    closeFn () {
      this.show = true
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
